<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<html>
<head>
    <title>Title</title>
    <script>
        window.onload = function() {
            var deadline = new Date('${exam.terminaltime}').getTime(); //获取从服务器返回的截止时间
            var countdown = document.getElementById('countdown'); //获取用来显示倒计时的元素
            var interval = setInterval(function() {
                var now = new Date().getTime();
                var remaining = deadline - now;  //剩余时间 = 截止时间 - 当前时间

                var days = Math.floor(remaining / (1000 * 60 * 60 * 24));
                var hours = Math.floor((remaining % (1000 * 60 * 60 * 24)) / (1000 * 60 * 60));
                var minutes = Math.floor((remaining % (1000 * 60 * 60)) / (1000 * 60));
                var seconds = Math.floor((remaining % (1000 * 60)) / 1000);

                countdown.innerHTML = days + "天 " + hours + "小时 " + minutes + "分钟 " + seconds + "秒 " + "剩余";

                if (remaining < 0) {  // 如果已达到截止时间
                    clearInterval(interval); // 清除定时器
                    countdown.innerHTML = "时间到！";
                }
            }, 1000);
        }
    </script>
</head>
<body>
<div id="countdown"></div>
</body>
</html>
